extends Node

@onready var player = $Player
@onready var spawn_location = $SpawnPath/SpawnLocation
@onready var mob_timer = $MobTimer
@onready var score_label = $UserInterface/ScoreLabel
@onready var retry = $UserInterface/Retry

@export var mob_scene : PackedScene

func _ready():
	retry.hide()

func _on_mob_timer_timeout():
	var mob = mob_scene.instantiate()
	spawn_location.progress_ratio = randf()
	
	var player_position = player.position
	mob.initalize(spawn_location.position, player_position)
	
	add_child(mob)
	
	mob.squashed.connect(score_label._on_mob_squashed.bind())


func _on_player_hit():
	mob_timer.stop()
	retry.show()

func _unhandled_input(event):
	if retry.visible and event.is_action_pressed("ui_accept"):
		get_tree().reload_current_scene()
